import { timeoutTask, getRandom, showWxToast } from '../../utils/index';
import { getPoolMoney, getNynInfo, getNynRank, nynRecharge, startNyn, sendPrizeInfo, sendBroadCast } from '../../api/nyn/nyn';
import { wxPay } from '../../api/pay';
import defaultContent from '../../assets/constant/default';

const app = getApp();
// 蛋位置信息
const locatInfo = [
    {
        x: 118,
        y: 0,
        fallAniDelay: 0.2,
        rotateAniDelay: 0.1,
        upAniDelay: 1.6,
        rotateAniDelay2: 1.5,
    },
    {
        x: 258,
        y: 26,
        fallAniDelay: 0.4,
        rotateAniDelay: 0.3,
        upAniDelay: 1.4,
        rotateAniDelay2: 1.3,
    },
    {
        x: 392,
        y: 62,
        fallAniDelay: 0.6,
        rotateAniDelay: 0.5,
        upAniDelay: 1.2,
        rotateAniDelay2: 1.1,
    },
    {
        x: 0,
        y: 80,
        fallAniDelay: 0.8,
        rotateAniDelay: 0.7,
        upAniDelay: 1,
        rotateAniDelay2: 0.9,
    },
    {
        x: 124,
        y: 128,
        fallAniDelay: 1,
        rotateAniDelay: 0.9,
        upAniDelay: 0.8,
        rotateAniDelay2: 0.7,
    },
    {
        x: 264,
        y: 162,
        fallAniDelay: 1.2,
        rotateAniDelay: 1.1,
        upAniDelay: 0.6,
        rotateAniDelay2: 0.5,
    },
    {
        x: 412,
        y: 192,
        fallAniDelay: 1.4,
        rotateAniDelay: 1.3,
        upAniDelay: 0.4,
        rotateAniDelay2: 0.3,
    },
    {
        x: 8,
        y: 212,
        fallAniDelay: 1.6,
        rotateAniDelay: 1.5,
        upAniDelay: 0.2,
        rotateAniDelay2: 0.1,
    },
]
// 蛋类型
const eggType = [
    {
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/egg1-01.png',
        width: 141,
        height: 155,
        luckyBeginY: -148,
    }, {
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/egg2.png',
        width: 141,
        height: 140,
        luckyBeginY: -136,
    }, {
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/egg3.png',
        width: 141,
        height: 140,
        luckyBeginY: -136,
    }, {
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/egg4-01.png',
        width: 141,
        height: 141,
        luckyBeginY: -140,
    },
];
// 礼物数组
const giftList = [
    {
        id: 1,
        gift: 'rocket1',
        name: '小号火箭',
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/rocket1.png',
        isChoosed: true
    }, {
        id: 2,
        gift: 'rocket2',
        name: '中号火箭',
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/rocket2.png',
        isChoosed: false
    }, {
        id: 3,
        gift: 'rocket3',
        name: '大号火箭',
        imgUrl: 'https://static.hudongmiao.com/joymewMp/nyn/rocket3.png',
        isChoosed: false
    }
];
const wishList = [
    '醉酒饱德，不胜感激',
    '美酒佳肴,不甚荣幸',
    '感谢招待,祝愿安康',
    '小小红包,感谢招待'
];

let tmpInterval; //用于倒计时
let tmpInterval2; //用于轮询
let lock = false; //锁，用于确保 倒计时方法 一轮只调用一次
let lock2 = false;//锁，用于确保 执行动画的过程中不可以点按钮
let lock3 = false;//锁，用于确保 开始游戏按钮不能连续点击
Page({
    data: {
        gameStatus: 1, // 游戏状态(控制页面显示)
        eggList: [], // 扭蛋列表
        prizeItemList: [],// 奖项列表
        poolMoney: 0, //奖池金额
        countDownNum: 0,// 倒计时
        isEntry: false,// 充值入口
        rechargeTipList: [], //充值提示列表
        luckyTipList: [], //中奖提示列表
        topRankList: [],// 排行榜列表
        otherRankList: [],
        isRechargeTipShow: false, //控制充值提示显示隐藏
        isResultTipShow: false, //控制扭一扭结果提示显示隐藏
        user: {
            nickname: 'player',
            money: 0
        }, //充值用户
        resultTipContent: {
            resultImgSrc: '',
            para1: '',
            para2: '',
            result: '',
            ptVal: 44,
        }, //充值结果内容
        btnText: '发送礼物',
        userId: '',
        openId: '',
        name: '',
        headImg: '',
        turnId: '', //一场游戏的id 0代表要充值 否则代表这场游戏的场id
        giftList: giftList,
        giftListShow: true,
        rechargeTipAni: '',
        resultTipAni: '',
        luckyEgg: {
            imgUrl: '',
            width: '',
            height: '',
            luckyBeginY: 0,
            luckyEndY: 0,
            isFallLuckyAni: false,
            isRotateAni: false,
            left: 22,
            top: -124,
        },
    },
    onLoad: function (options) {
        tmpInterval = null;
        tmpInterval2 = null;
        lock = false;
        lock2 = false;
        lock3 = false;
        this.setData({
            userId: options.userId,
            openId: options.openId,
            name: options.name,
            headImg: options.headImg,
            prizeItemList: app.globalData.nynList,
        });
        this.requestPoolMoney();
        this.initEggList();
    },
    onShow: function () {
        this.toGame();
    },
    onHide: function () {
        //清除定时器
        clearInterval(tmpInterval);
        clearInterval(tmpInterval2);
        tmpInterval = null;
        tmpInterval2 = null;
        lock = false;
    },
    onUnload: function () {
        //清除定时器
        clearInterval(tmpInterval);
        clearInterval(tmpInterval2);
        tmpInterval = null;
        tmpInterval2 = null;
    },
    initEggList() {
        let tmpEggList = [];
        const len = this.data.prizeItemList.length;
        console.log(this.data.prizeItemList);
        for (let i = 0; i < len; i += 1) {
            this.createEgg(tmpEggList, i);
        }
        this.setData({
            eggList: tmpEggList,
        });
    },
    createEgg(tmArr, num) {
        let typeIndex = num > 3 ? num - 4 : num;
        let tmpDesc;
        if (this.data.prizeItemList[num]) {
            tmpDesc = this.data.prizeItemList[num].desc;
        } else {
            tmpDesc = '谢谢参与';
        }
        console.log(eggType, typeIndex);
        const egg = {
            num: num + 1,
            imgUrl: eggType[typeIndex].imgUrl,
            width: eggType[typeIndex].width,
            height: eggType[typeIndex].height,
            left: locatInfo[num].x,
            bottom: locatInfo[num].y,
            fallAniDelay: locatInfo[num].fallAniDelay,
            rotateAniDelay: locatInfo[num].rotateAniDelay,
            isFallAni: false,
            aroundAni: '',
            isRotateAni: false,
            prize: tmpDesc,
        };
        tmArr.push(egg);
    },
    fallEgg() {
        let tmpEggList = this.data.eggList;
        for (let i = 0; i < 8; i += 1) {
            tmpEggList[i].isFallAni = true;
            tmpEggList[i].isRotateAni = true;
        }
        this.setData({
            eggList: tmpEggList
        });
        timeoutTask(() => {
            for (let i = 0; i < 8; i += 1) {
                tmpEggList[i].isFallAni = false;
                tmpEggList[i].isRotateAni = false;
            }
            this.setData({
                eggList: tmpEggList
            });
        }, 2000);
    },
    beginAroundAni() {
        let tmpEggList = this.data.eggList;
        for (let i = 0; i < 8; i += 1) {
            tmpEggList[i].fallAniDelay = locatInfo[i].upAniDelay;
            tmpEggList[i].rotateAniDelay = locatInfo[i].rotateAniDelay2;
            this.setData({
                eggList: tmpEggList
            });
            // timeoutTask(() => {
            tmpEggList[i].isRotateAni = true;
            tmpEggList[i].aroundAni = `aroundAni${tmpEggList[i].num}`;
            this.setData({
                eggList: tmpEggList
            });
            // }, 100);
        }
    },
    endAroudAni() {
        let tmpEggList = this.data.eggList;
        for (let i = 0; i < 8; i += 1) {
            tmpEggList[i].isRotateAni = false;
            tmpEggList[i].aroundAni = '';
        }
        this.setData({
            eggList: tmpEggList
        });
    },
    handleStartBtnTap() {
        if (this.data.btnText === '发送礼物') {
            //判断是否选中某个礼物
            const resultIndex = this.data.giftList.findIndex((item) => {
                return item.isChoosed;
            });
            if (resultIndex > -1) {
                console.log(resultIndex);
                if (this.data.isEntry) {
                    // 充值入口开着
                    this.recharge();
                } else {
                    // 最后十五秒购买入口关闭
                    showWxToast('购买入口关闭');
                }
            } else {
                showWxToast('请选择一个礼物');
            }
        }
    },
    tapstartNyn() {
        getNynInfo().then((res) => {
            console.log(res);
            this.setData({
                turnId: res.data.id
            });
            this.startGame();
        }).catch((err) => {
            console.log(err);
            showWxToast('网络异常');
        });
    },
    // 选择礼物
    chooseGift(e) {
        console.log(e)
        const choosedId = e.currentTarget.dataset.id;
        const tmpGiftList = this.data.giftList;
        tmpGiftList.forEach(item => {
            if (item.id === choosedId) {
                item.isChoosed = true;
            } else {
                item.isChoosed = false;
            }
        });
        this.setData({
            giftList: tmpGiftList
        });
    },
    // 扭一扭动画
    gameAniStart(endIndex, endMoney) {
        this.beginAroundAni();
        timeoutTask(() => {
            console.log('***5s后结束扭一扭动画 展示luckyEgg***');
            this.endAroudAni();
            this.showLuckyEgg(endIndex, endMoney);
        }, 5000);
        timeoutTask(() => {
            console.log('***6s后 展示resultTip***');
            this.showResultTip(endIndex, this.data.name, endMoney);
        }, 6000);
        timeoutTask(() => {
            console.log('***10s后恢复状态***');
            this.setData({
                btnText: '发送礼物',
                giftListShow: true,
            });
        }, 10000);
    },
    // 充钱玩扭一扭
    recharge() {
        if (lock2) {
            return;
        }
        lock2 = true;
        nynRecharge({
            userId: this.data.userId,
            openId: this.data.openId,
        }).then((res) => {
            console.log(res);
            return wxPay(res);
        }).then(() => {
            showWxToast('礼物发送成功!');
            this.sendGift(this.getChoosedGift());
            //充值成功按钮状态立即改变
            this.setData({
                btnText: '扭一扭',
                giftListShow: false,
            });
            // startGame
            timeoutTask(() => {
                // this.handleStartBtnTap();
                console.log('***2s后自动扭一扭***')
                this.tapstartNyn();
            }, 2000);

        }).catch((err) => {
            console.log(err);
            lock2 = false;
            showWxToast('支付失败!');
        });
    },
    getChoosedGift() {
        return this.data.giftList.find(item => {
            return item.isChoosed;
        });
    },
    sendGift(giftChoosed) {
        let tmpCode = '';
        if (giftChoosed.id == 1) {
            tmpCode = 5002;
        } else if (giftChoosed.id == 2) {
            tmpCode = 6002;
        } else if (giftChoosed.id == 3) {
            tmpCode = 7002;
        }
        const c = JSON.stringify({
            code: tmpCode,
            param: {
                headImg: this.data.headImg,
                nickname: this.data.name,
                wish: wishList[parseInt(Math.random() * 3)]
            }
        });
        sendBroadCast({
            c,
        });
    },
    // 扭一扭
    startGame() {
        startNyn({
            turnId: this.data.turnId,
        }).then((res) => {
            console.log('startNyn result:', res);
            //res.data.desc 奖项；endMoney中奖的金额；totalMoney 奖池金额
            //奖池金额刷新
            if (res.data.totalMoney.balance) {
                this.setData({
                    poolMoney: res.data.totalMoney.balance
                })
            }
            //游戏动画开始
            this.gameAniStart(res.data.lotteryType, res.data.endMoney);

            // 5s动画停止后发送广播(必须要中奖的情况)
            if (parseInt(res.data.endMoney) > 0) {
                timeoutTask(() => {
                    this.sendBroad(res.data.endMoney, res.data.totalMoney.balance);
                }, 5000);
            }
            timeoutTask(() => {
                lock2 = false;
            }, 5000);
        }).catch((err) => {
            console.log(err);
            lock2 = false;
        });
    },
    // 点击进入游戏
    toGame() {
        if (lock3) {
            return;
        }
        lock3 = true;
        this.requestGameInitInfo();
    },
    // 获取奖池金额
    requestPoolMoney() {
        getPoolMoney().then((res) => {
            console.log(res);
            this.setData({
                poolMoney: res.data.balance
            });
        }).catch((err) => {
            console.log(err);
        });
    },
    // 获取游戏相关信息
    requestGameInitInfo() {
        getNynInfo().then((res) => {
            console.log('***获取扭一扭基本信息***');
            console.log(res);
            //res.data.id 发送礼物 1扭一扭
            if (res.data.id == 0) {
                this.setData({
                    btnText: '发送礼物',
                    giftListShow: true,
                    turnId: res.data.id
                })
            } else {
                this.setData({
                    btnText: '扭一扭',
                    giftListShow: false,
                    turnId: res.data.id
                })
            }
            // 时间处理(用于倒计时) res.data.endTime
            if (res.data.endTime === '0') {
                // 游戏未开始的情况处理
                showWxToast('游戏尚未开始!');
            } else {
                let countTime = this.timeHandle(res.data.endTime);
                console.log('***接口返回endTime***');
                console.log(res.data.endTime);
                this.countDown(countTime);
                this.setData({
                    gameStatus: 2,
                });
                this.fallEgg();
                // 轮询获取充值和中奖列表
                if (!tmpInterval2) {
                    tmpInterval2 = setInterval(() => {
                        console.log('tmpInterval2');
                        this.noticeShow();
                    }, 4000);
                }
            }
            lock3 = false;
        }).catch((err) => {
            console.log(err);
            lock3 = false;
        });
    },
    // 获取充值和中奖列表
    requestTipList() {
        let tmpLuckyTipList = [];
        let tmpRechargeTipList = [];
        getPoolMoney().then((res) => {
            console.log('***getPoolMoney***', res);
            const subTime = this.timeHandle(res.data.endTime);
            if (subTime <= 0) {
                // 游戏提前结束
                this.requestRankList();
            }
            for (let i = 0; i < res.data.list.length; i += 1) {
                tmpRechargeTipList.push({
                    nickname: res.data.list[i].wx_name,
                    money: res.data.list[i].gsum,
                });
                if (parseInt(res.data.list[i].c01) > 0) { //确保 “谢谢参与的” 奖项不弹出
                    tmpLuckyTipList.push({
                        nickname: res.data.list[i].wx_name,
                        endMoney: res.data.list[i].c01
                    })
                }
            }
            this.setData({
                rechargeTipList: tmpRechargeTipList,
                luckyTipList: tmpLuckyTipList,
                poolMoney: res.data.balance
            });
        }).catch((err) => {
            console.log(err);
        })
    },
    // 时间戳处理
    timeHandle(endTime) {
        //获取当前时间戳
        var nowTime = (new Date()).getTime();
        var subTime = parseInt((parseInt(endTime) - parseInt(nowTime)) / 1000);
        if (subTime < 0) {
            subTime = 0;
        }
        return subTime;
    },
    // 不带毫秒的倒计时
    countDown(second) {
        if (lock == false && !tmpInterval) {
            lock = true;
            tmpInterval = setInterval(() => {
                console.log('tmpInterval');
                if (second <= 1) {
                    this.setData({
                        isEntry: false,
                        countDownNum: second
                    })
                    this.requestRankList();
                } else {
                    second -= 1;
                    if (second <= 7) {
                        this.setData({
                            isEntry: false
                        })
                    } else {
                        this.setData({
                            isEntry: true
                        })
                    }
                    this.setData({
                        countDownNum: second
                    })
                }

            }, 1000)
        }
    },
    // 弹出消息(包括充值和中奖)
    noticeShow() {
        if (this.data.rechargeTipList[app.globalData.nynRechargeIndex] && this.data.isRechargeTipShow == false) {
            //当前存在未弹出的充值消息
            let tmpObj = {};
            tmpObj.nickname = this.data.rechargeTipList[app.globalData.nynRechargeIndex].nickname;
            tmpObj.money = this.data.rechargeTipList[app.globalData.nynRechargeIndex].money;
            this.setData({
                user: tmpObj
            })
            //调用showRechargeTip方法
            this.showRechargeTip();
        } else {
            //更新数组
            this.requestTipList();
        }
        if (this.data.luckyTipList[app.globalData.nynLuckyIndex] && this.data.isResultTipShow == false) {
            //当前存在未弹出的中奖消息
            let tmpObj = {};
            tmpObj = this.data.luckyTipList[app.globalData.nynLuckyIndex];
            //loopShowResultTip
            this.loopShowResultTip(tmpObj.nickname, tmpObj.endMoney);
        } else {
            //更新数组
            this.requestTipList();
        }
    },
    // 获取排行榜列表
    requestRankList() {
        getNynRank().then((res) => {
            console.log(res);
            lock = false;
            let tmpTopRankArray = [];
            let tmpOtherRankArray = [];
            let count = 0;
            let tmpLen = res.data.list.length;
            // 限制中奖名单人数最多不超过10个
            if (tmpLen > 10) {
                tmpLen = 10;
            }
            while (count < tmpLen) {
                if (count < 3) {
                    tmpTopRankArray.push({
                        nickname: res.data.list[count].wx_name,
                        headimgurl: res.data.list[count].avator,
                        money: Math.floor(parseFloat(res.data.list[count].money))
                    });
                } else {
                    tmpOtherRankArray.push({
                        num: count < 0 ? `0${count + 1}` : (count + 1),
                        nickname: res.data.list[count].wx_name,
                        headimgurl: res.data.list[count].avator,
                        money: Math.floor(parseFloat(res.data.list[count].money))
                    });
                }
                count += 1;
            }
            if (tmpTopRankArray.length < 3) {
                const tmpLen2 = tmpTopRankArray.length;
                for (let i = tmpLen2; i < 3; i += 1) {
                    tmpTopRankArray.push({
                        nickname: 'Player',
                        headimgurl: defaultContent.defaultHeadImg,
                        money: 0,
                    });
                }
            }
            // 不足七个补齐
            if (tmpOtherRankArray.length < 7) {
                const tmpLen3 = tmpOtherRankArray.length;
                for (let i = tmpLen3; i < 7; i += 1) {
                    tmpOtherRankArray.push({
                        num: i + 3 < 0 ? `0${i + 4}` : (i + 4),
                        nickname: 'Player',
                        headimgurl: defaultContent.defaultHeadImg,
                        money: 0,
                    });
                }
            }

            console.log(tmpOtherRankArray);
            this.setData({
                topRankList: tmpTopRankArray,
                otherRankList: tmpOtherRankArray,
                gameStatus: 3,
            });
            // 停止轮询
            clearInterval(tmpInterval2);
            clearInterval(tmpInterval);
            tmpInterval = null;
            tmpInterval2 = null;
        }).catch((err) => {
            console.log(err);
        });
    },
    showRechargeTip() {
        this.setData({
            isRechargeTipShow: true
        });
        this.setData({
            rechargeTipAni: 'rechargeTipAni'
        });
        timeoutTask(() => {
            this.setData({
                rechargeTipAni: 'rechargeTipAni2'
            });
        }, 3000);
        timeoutTask(() => {
            this.setData({
                isRechargeTipShow: false
            });
            app.updateNynRechargeIndex();
        }, 4000);
    },
    loopShowResultTip(pNickname, money) {
        let nickname = pNickname || '匿名';
        if (parseInt(money) > 0) {
            //抽中
            let result = {
                resultImgSrc: 'https://static.hudongmiao.com/joymewMp/nyn/happyMew-01.png',
                para1: '恭喜' + nickname,
                para2: '获得' + money + '奖励',
                result: 1,
                ptVal: 34,
            };
            this.setData({
                resultTipContent: result,
                isResultTipShow: true,
                resultTipAni: 'resultTipAni',
            });
            timeoutTask(() => {
                this.setData({
                    resultTipAni: 'resultTipAni2'
                });
            }, 4000);
            timeoutTask(() => {
                this.setData({
                    isResultTipShow: false
                });
                app.updateNynLuckyIndex();
            }, 4000);
        } else {
            //未抽中
            let result = {
                resultImgSrc: 'https://static.hudongmiao.com/joymewMp/nyn/sadMew-01.png',
                para1: '很遗憾没有抽中',
                para2: '谢谢惠顾，再接再厉',
                result: 0,
                ptVal: 44,
            };
            this.setData({
                resultTipContent: result,
                isResultTipShow: true,
                resultTipAni: 'resultTipAni',
            });
            timeoutTask(() => {
                this.setData({
                    resultTipAni: 'resultTipAni2'
                });
            }, 4000);
            timeoutTask(() => {
                this.setData({
                    isResultTipShow: false
                });
            }, 4000);
        }
    },
    showResultTip(num, pNickname, money) {
        console.log('***showReusltTip***');
        console.log(this.data.prizeItemList);
        console.log(num);
        let desc;
        if (this.data.prizeItemList[parseInt(num)]) {
            desc = this.data.prizeItemList[parseInt(num)].desc;
        } else {
            desc = '谢谢参与';
        }
        let nickname = pNickname || '匿名';
        if (money) {
            desc = money;
        }
        if (num == 0) {
            //未抽中
            let result = {
                resultImgSrc: 'https://static.hudongmiao.com/joymewMp/nyn/sadMew-01.png',
                para1: '很遗憾没有抽中',
                para2: '谢谢惠顾，再接再厉',
                result: 0,
                ptVal: 44,
            };
            this.setData({
                resultTipContent: result,
                isResultTipShow: true,
                resultTipAni: 'resultTipAni',
            });
            timeoutTask(() => {
                this.setData({
                    resultTipAni: 'resultTipAni2'
                });
            }, 4000);
            timeoutTask(() => {
                this.setData({
                    isResultTipShow: false
                });
            }, 4000);
        } else {
            //抽中
            let result = {
                resultImgSrc: 'https://static.hudongmiao.com/joymewMp/nyn/happyMew-01.png',
                para1: '恭喜' + nickname,
                para2: '获得' + desc + '奖励',
                result: 1,
                ptVal: 34,
            };
            this.setData({
                resultTipContent: result,
                isResultTipShow: true,
                resultTipAni: 'resultTipAni',
            });
            timeoutTask(() => {
                this.setData({
                    resultTipAni: 'resultTipAni2'
                });
            }, 4000);
            timeoutTask(() => {
                this.setData({
                    isResultTipShow: false
                });
                app.updateNynLuckyIndex();
            }, 4000);
        }
    },
    // 发广播
    sendBroad(golds, remainCoins) {
        sendPrizeInfo({
            gold: golds,
            remainCoin: remainCoins,
            turnId: this.data.turnId,
        }).then((res) => {
            console.log(res);
        }).catch((err) => {
            console.log(err);
            showWxToast('网络异常');
        });
    },
    // 蛋掉落 从蛋下落并停留到消失 耗时 3s
    showLuckyEgg(endIndex, endMoney) {
        this.createLuckyEgg(endIndex, endMoney);
        const tmpLuckyEgg = this.data.luckyEgg;
        tmpLuckyEgg.top = this.data.luckyEgg.luckyBeginY;
        console.log('***蛋下落动画执行***');
        tmpLuckyEgg.isFallLuckyAni = true;
        tmpLuckyEgg.isRotateAni = true;
        this.setData({
            luckyEgg: tmpLuckyEgg,
        });
        // 下落后保持在终点位置
        timeoutTask(() => {
            tmpLuckyEgg.end = 208;
            tmpLuckyEgg.isRotateAni = false;
            console.log('***保持在终点位置***');
            this.setData({
                luckyEgg: tmpLuckyEgg,
            });
        }, 1000);
        timeoutTask(() => {
            console.log('***回到初始位置***');
            tmpLuckyEgg.isFallLuckyAni = false;
            tmpLuckyEgg.end = '';
            tmpLuckyEgg.top = this.data.luckyEgg.luckyBeginY;
            this.setData({
                luckyEgg: tmpLuckyEgg,
            });
        }, 4000);
    },
    // 创建中奖扭蛋
    createLuckyEgg(num, money) {
        console.log('***createLuckyEgg***');
        console.log(num, money);
        console.log(this.data.prizeItemList);
        const eggTypeIndex = getRandom(0, 4);
        const tmpLuckyEgg = this.data.luckyEgg;
        tmpLuckyEgg.imgUrl = eggType[eggTypeIndex].imgUrl;
        tmpLuckyEgg.width = eggType[eggTypeIndex].width;
        tmpLuckyEgg.height = eggType[eggTypeIndex].height;
        tmpLuckyEgg.luckyBeginY = eggType[eggTypeIndex].luckyBeginY;
        let desc;
        if (this.data.prizeItemList[parseInt(num)]) {
            desc = this.data.prizeItemList[parseInt(num)].desc;
        }
        if (money) {
            desc = money;
        }
        if (num == 0) {
            desc = '谢谢参与';
        }
        tmpLuckyEgg.prize = desc;
        this.setData({
            luckyEgg: tmpLuckyEgg,
        });
    },
    toAgreement: function () {
        wx.navigateTo({
            url: '/pages/agreement/agreement'
        });
    },
});